package com.lottery.ruok.lottrey.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.google.gson.JsonElement;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.fragment.LoginOrderMainFragment;
import com.lottery.ruok.lottrey.retrofitModule.RetrofitBase;
import com.lottery.ruok.lottrey.retrofitModule.RxHelper;
import com.lottery.ruok.lottrey.retrofitModule.RxSubscribe;
import com.lottery.ruok.lottrey.retrofitModule.request.GetHasSMSRequest;
import com.lottery.ruok.lottrey.retrofitModule.response.GetHasSMSResponse;
import com.lottery.ruok.lottrey.userInfo.UserInfo;

import butterknife.BindView;
import butterknife.ButterKnife;
import ui.NavigateBar;
/*
* 投注记录
* */

public class OrderActivity extends BaseActivity {
    public String ANALYTIC_VERSION = "1.0";

    @BindView(R.id.navigateBar)
    NavigateBar navigateBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);

        ButterKnife.bind(this);

        init();
    }

    private void init() {
        navigateBar.setOnOperateClickListener(new NavigateBar.OnOperateClickListener() {
            @Override
            public void onOperateClick(View view) {
                //sendAnalyticMsg("lottery_" + ANALYTIC_VERSION + "_betrecord_summary_jump");

                gotoSummaryActivity();
            }
        });

        LoginOrderMainFragment loginOrderMainFragment = new LoginOrderMainFragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean("from_buy", getIntent().getBooleanExtra("from_buy", false));
        loginOrderMainFragment.setArguments(bundle);
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction ft = manager.beginTransaction();
        ft.replace(R.id.fragment_my_order_lists, loginOrderMainFragment);
        ft.commitAllowingStateLoss();
        getOrderEnableWithdrawalConfig();
    }

    private void getOrderEnableWithdrawalConfig(){
        RetrofitBase.getRetrofit().create(GetHasSMSRequest.class).getResult("enable_withdrawal")
                .compose(RxHelper.<GetHasSMSResponse>handleResult())
                .subscribe(new RxSubscribe<GetHasSMSResponse>(this){

                    @Override
                    protected void _onNext(GetHasSMSResponse getHasSMSResponse) {
                        if (getHasSMSResponse != null && getHasSMSResponse.getValue() != null) {
                            int  enable_withdrawal = getHasSMSResponse.getValue().getAsInt();
                            UserInfo.setEnableWithdrawal(enable_withdrawal);
                        }
                    }

                    @Override
                    protected boolean showDialog() {
                        return false;
                    }
                });

    }
}